<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Api\AuthController;
use App\Api\CaptchaController;
use App\Api\UserController;
use App\Api\SiteController;
use App\Api\SystemConfigController;
use App\Api\UploadController;
use App\Api\PackageController;
use App\Api\GroupController;
use App\Api\ModuleController;
use App\Api\RoleController;
use App\Api\PermissionController;
use App\Api\CodeController;
use App\Api\ModuleConfigController;
use App\WeChat\WeChatController;

//登录注册
Route::post('login', [AuthController::class, 'login']);
Route::get('captcha', [CaptchaController::class, 'create']);
Route::get('user/info', [UserController::class, 'info']);
Route::put('user/password', [UserController::class, 'password']);
Route::apiResource('user', UserController::class);
//用户相关
Route::put('site/{site}/user/email', [UserController::class, 'email']);
Route::put('site/{site}/user/mobile', [UserController::class, 'mobile']);
//站点
Route::get('site/current', [SiteController::class, 'current']);
Route::get('site/{site}/permission/sync', [SiteController::class, 'permission']);
Route::apiResource('site', SiteController::class);
//验证码
Route::post('site/{site}/code/mobile', [CodeController::class, 'mobile'])->middleware(['auth:sanctum', 'site']);
Route::post('site/{site}/code/mobile/noexist', [CodeController::class, 'mobileNoExist'])->middleware(['site']);
Route::post('site/{site}/code/email', [CodeController::class, 'email'])->middleware(['auth:sanctum', 'site']);
Route::post('site/{site}/code/email/noexist', [CodeController::class, 'emailNoExist'])->middleware(['site']);
//系统配置
Route::apiResource('system/config', SystemConfigController::class)->only(['store', 'show']);
//模块配置
Route::put('module/config/site/{site}/module/{module}', [ModuleConfigController::class, 'update']);
//上传
Route::post('upload/local', [UploadController::class, 'local']);
Route::post('upload/site/{site}', [UploadController::class, 'site']);
Route::post('upload/site/{site}/wangeditor', [UploadController::class, 'wangEditor']);
//套餐
Route::apiResource('package', PackageController::class);
//会员组
Route::apiResource('group', GroupController::class);
//模块
Route::get('module/user', [ModuleController::class, 'user']);
Route::get('module/installed', [ModuleController::class, 'installed']);
Route::apiResource('module', ModuleController::class)->scoped(['module' => 'name']);
Route::get('site/{site}/module', [ModuleController::class, 'site']);
//角色
Route::apiResource('site.role', RoleController::class);
//权限
Route::get('site/{site}/permission', [PermissionController::class, 'site']);
Route::put('site/{site}/role/{role}/permission', [PermissionController::class, 'role']);

//微信公众号管理
Route::apiResource('site/{site}/wechat', WeChatController::class);